package com.atguigu.flink.chapter05.source;

import jdk.nashorn.internal.runtime.regexp.joni.Config;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/*
    从集合中读取数据
 */
public class ListSource {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port",20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(2);

        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);

        //DataStreamSource<Integer> stream = env.fromCollection(list);
        DataStreamSource<Integer> stream = env.fromElements(1, 4, 5, 668, 89);
        stream.print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


//public class ListSource {
//    public static void main(String[] args) {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",20000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(2);
//
//        List<Integer> list = Arrays.asList(23, 45, 76, 87);
//        //DataStreamSource<Integer> stream = env.fromCollection(list);
//
//        DataStreamSource<Integer> stream = env.fromElements(23, 45, 65, 78, 90);
//        stream.print();
//
//        try {
//            env.execute();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}

//public class ListSource {
//    public static void main(String[] args) {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",20000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(2);
//
//        //List<Integer> list = Arrays.asList(23, 45, 78, 89, 90);
//        //DataStreamSource<Integer> stream = env.fromCollection(list);
//
//        DataStreamSource<Integer> stream = env.fromElements(34, 65, 78, 89, 90);
//
//        stream.print();
//        try {
//            env.execute();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}